<template>
	<view class="bg-white padding-tb padding-lr-xl min-height-100 text-lg">
		<EventBasicDetail :event-id="params.eventId" :data.sync="info">
			<!-- v-if="isStaff && status!==EventStatusMap.completedVal" -->
			<block v-if="isStaff && Number(eventStatus) !==EventStatusMap.completedVal && !isHistory">
				<view slot="custom">
					<EventNodeFlow :instance-id="instanceId" :event-subclass="eventSubclass" :event-type-id="eventTypeId" :current-node-id="currentNodeId" :next-node-id="nextNodeId"
						:current-task-id="taskId" :lat="lat" :lon="lon" @handle="onNextHandle" />
				</view>
			</block>
		</EventBasicDetail>
	</view>
</template>

<script>
	import {
		setEventHandle
	} from "@/api/Interface/event"
	import EventBasicDetail from "../components/EventBasicDetail.vue"
	import {
		RoleEnum
	} from "@/enums/role"
	import {
		mapState
	} from "vuex"
	import EventNodeFlow from "../components/EventNodeFlow/EventNodeFlow.vue"
	import {
		ActionMap,
		ActionEnum,
		ActionConfig
	} from "@/enums/actions"
	import {
		EventStatusMap
	} from "@/enums/event"
	import {
		PathEnum
	} from "../../../utils/path.config"
	export default {
		components: {
			EventBasicDetail,
			EventNodeFlow
		},
		data() {
			return {
				EventStatusMap,
				ActionMap,
				ActionEnum,
				ActionConfig,
				message: "数据加载中...",
				info: null,
				currentNodeId: null,
				nextNodeId: null,
				taskId: null,
				lat: null,
				lon: null,
				params: {
					eventHandler: null,
					eventId: null,
					taskAction: null
				},
				status: null, // 事件处理状态
				eventSubclass: null,
				eventTypeId: null,
				instanceId: null,
				isHistory: true,
			}
		},
		async onLoad(options) {
			this.params.eventId = options.id;
			this.currentNodeId = options.currentNodeId;
			this.nextNodeId = options.nextNodeId;
			this.taskId = options.taskId;
			this.lat = options.lat;
			this.lon = options.lon;
			this.eventSubclass = options.eventSubclass;
			this.eventTypeId = options.eventTypeId;
			this.instanceId = options.instanceId;
			this.isHistory = options.history === PathEnum.history;
			const status = Number(options.status);
			uni.$u.test.number(status) && (this.status = status);
		},
		computed: {
			...mapState('user', {
				roles: state => state.roles
			}),
			isStaff() {
				console.log("this.roles", this.roles, RoleEnum.staff, this.roles.findIndex(f => f.roleKey === RoleEnum.staff));
				return this.roles.findIndex(f => f.roleKey === RoleEnum.staff) >= 0;
			},
			descPopupShow() {
				return [ActionMap.refuseVal, ActionMap.failVal].includes(this.params.taskAction)
			},
			eventStatus() {
				return this.info?.data?.eventStatus
			},
			eventInfo() {
				return this.info
			}
		},
		methods: {
			onNextHandle(e) {
				const {
					taskAction,
					eventHandler,
					params
				} = e;

				this.params.eventHandler = eventHandler;
				this.params.taskAction = taskAction;
				this.params = Object.assign({}, this.params, params)
				console.log("处理参数", this.params);
				let me = this;
				if (taskAction !== ActionMap.failVal && this.nextNodeId && uni.$u.test.empty(this.params.eventHandler)) {
					this.$toast("请选择下一节点处理人")
					return;
				}
				uni.showModal({
					title: "确认提交?",
					async success(modalRes) {
						if (modalRes.confirm) {
							me.$loadToast("提交中...")
							await setEventHandle(me.params).then(res => {
								me.$toast(res.msg)
								if (res.code === 200) {
									setTimeout(() => {
										uni.navigateBack({
											delta: 1
										})
									}, 1500)
								}
							})
							uni.hideLoading()
						}
					}
				})

			},
		},
	}
</script>

<style lang="less" scoped>
</style>